package com.lcc.codehelper.util;

import cn.hutool.core.util.StrUtil;
import com.google.common.base.CaseFormat;

/**
 * @author lincc
 * @version 1.0 2019/03/27
 * String 处理工具类
 */
public class StringUtil {

    public static String underLine2Camel(String str){
        return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, str);
    }

    public static String underLine2CamelFilterHead(String str){
        return CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, str.substring(str.indexOf("_")));
    }

    public static String underLine2CamelFilterHeadAndLowerHead(String str){
        String data = underLine2CamelFilterHead(str);
        //得到数据后再首字母小写
        return upperCase(data);
    }

    public static String tableNameUnderLine2CamelAndUpperHead(String str,Boolean splitByEnt){
        if (splitByEnt){
            str=str.substring(0,str.lastIndexOf("_"));
        }
        String data=StrUtil.toCamelCase(str);
        return StrUtil.upperFirst(data);
    }

    public static String tableNameUnderLine2CamelAndLowerHead(String str,Boolean splitByEnt){
        if (splitByEnt){
            str=str.substring(0,str.lastIndexOf("_"));
        }
        return StrUtil.toCamelCase(str);
    }

    public static String upperCase(String str){
        char[] ch = str.toCharArray();
        if(ch[0] >='A' && ch[0]<='Z'){
            ch[0] = (char)(ch[0] + 32);
        }
        return new String(ch);
    }



    public static void main(String[] args) {
        System.out.println(underLine2Camel("FINGARD_TRANSACTIONS_QT330001"));
        System.out.println(underLine2CamelFilterHead("FINGARD_TRANSACTIONS_QT330001"));
        System.out.println(underLine2CamelFilterHeadAndLowerHead("FINGARD_TRANSACTIONS_QT330001"));
        System.out.println(tableNameUnderLine2CamelAndUpperHead("FINGARD_TRANSACTIONS_QT330001",true));
        System.out.println(tableNameUnderLine2CamelAndLowerHead("FINGARD_TRANSACTIONS_QT330001",true));
    }
}
